package collection;

import java.util.ArrayList;
import java.util.List;

/**
 * List集合支持获取子集操作
 * List subList(int start,int end)
 * 获取集合指定范围内的子集
 *
 */
public class ListDemo3 {
    public static void main(String[] args) {
    List<Integer> list = new ArrayList<>();//集合只可以放引用数据类型
        for (int i = 0; i < 10; i++) {
            list.add(i);
        }
        System.out.println(list);//[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

        //获取[3-7]
        List<Integer> subList = list.subList(3,8);
        System.out.println(subList);//[3, 4, 5, 6, 7]

        //将子集每个元素都扩大10倍
        for (int i = 0; i < subList.size(); i++) {
            Integer num = subList.set(i,subList.get(i)*10);
            System.out.println(num);//3,4,5,6,7
        }
        System.out.println(subList);//[30, 40, 50, 60, 70]
        //操作子集就是操作原集合中的
        System.out.println(list);//[0, 1, 2, 30, 40, 50, 60, 70, 8, 9]

        //list集合中的2-8删除
        //获取索引2-9的子集, 清空子集
        list.subList(2,9).clear();
        System.out.println(list);//[0, 1, 9]
    }
}
